package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.dto.RecordStatusDto;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampApproveCancelVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampCreateApprovalVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampFilesApproveRespVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampFilesCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampFilesPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampFilesRespVO;
import com.cmc.cloud.cmclink.doc.vo.tblisustampfiles.TblisustampFilesUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.TblisustampFilesDO;
import com.cmc.cloud.cmclink.doc.service.TblisustampFilesService;

import static com.cmes.framework.common.pojo.CommonResult.success;


/**
 * {table.classComment}前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 申请明细信息")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL + "/stampFiles")
@Validated
public class TblisustampFilesController {

    @Resource
    private TblisustampFilesService tblisustampFilesService;

    @Operation(summary = "创建申请明细信息")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission({'doc:B/LIssuingStampApprove:addFile','doc:B/LIssuingStampApprove:subtable:submit'})")
    public CommonResult<Void> createTblisustampFiles(@Valid @RequestBody TblisustampFilesCreateReqVO createReqVO) {
        tblisustampFilesService.createTblisustampFiles(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新申请明细信息")
    @PostMapping("/update")
    public CommonResult<Void> updateTblisustampFiles(@Valid @RequestBody TblisustampFilesUpdateReqVO updateReqVO) {
        tblisustampFilesService.updateTblisustampFiles(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除申请明细信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:B/LIssuingStampApprove:subtable:delete')")
    public CommonResult<Void> deleteTblisustampFiles(@PathVariable("id") Long id) {
        tblisustampFilesService.deleteTblisustampFiles(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得申请明细信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:B/LIssuingStampApprove:subtable:delete')")
    public CommonResult<TblisustampFilesRespVO> getTblisustampFiles(@PathVariable("id") Long id) {
        TblisustampFilesDO tblisustampFiles = tblisustampFilesService.getTblisustampFiles(id);
        return CommonResult.success(BeanUtil.copyProperties(tblisustampFiles, TblisustampFilesRespVO.class));
    }

    @GetMapping("/getApproveInfo/{id}")
    @Operation(summary = "获得审批人审批内容")
    @UseResponsePropertyAdvice
    public CommonResult<TblisustampFilesApproveRespVO> getApproveInfo(@PathVariable("id") Long id) {
        TblisustampFilesApproveRespVO tblisustampApproveFiles = tblisustampFilesService.getTblisustampApproveFiles(id);
        return CommonResult.success(tblisustampApproveFiles);
    }

    @Operation(summary = "根据主ID获得申请明细信息")
    @Parameter(name = "id", description = "编号", required = true, example = "10")
    @GetMapping("/listByMainId/{mainId}")
    @UseResponsePropertyAdvice
    public CommonResult<List<TblisustampFilesRespVO>> getListByMainId(@PathVariable("mainId") Long mainId) {
        List<TblisustampFilesDO> list = tblisustampFilesService.getListByMainId(mainId);
        return CommonResult.success(BeanUtil.copyToList(list, TblisustampFilesRespVO.class));
    }


    @Operation(summary = "获得申请明细信息列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<TblisustampFilesRespVO>> getTblisustampFilesList(@RequestParam("ids") Collection<Long> ids) {
        List<TblisustampFilesDO> list = tblisustampFilesService.getTblisustampFilesList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, TblisustampFilesRespVO.class));
    }

    @Operation(summary = "获得申请明细信息分页")
    @PostMapping("/getPage")
    @PreAuthorize("@ss.hasPermission('doc:B/LIssuingStampRetrieve:search')")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<TblisustampFilesRespVO>> getTblisustampFilesPage(@Valid TblisustampFilesPageReqVO pageVO) {
        PageResult<TblisustampFilesDO> pageResult = tblisustampFilesService.getTblisustampFilesPage(pageVO);
        List<TblisustampFilesRespVO> respVOList = BeanUtil.copyToList(pageResult.getList(), TblisustampFilesRespVO.class);
        return CommonResult.success(new PageResult<>(respVOList, pageResult.getTotal()));
    }

    @Operation(summary = "提交或审核申请明细")
    @PostMapping("/operate")
    @PreAuthorize("@ss.hasPermission({'doc:B/LIssuingStampRetrieve:accpect','doc:B/LIssuingStampRetrieve:refuse','doc:B/LIssuingStampApprove:subtable:cancel'})")
    public CommonResult<Void> commitOrCancelApprove(@RequestBody @Valid RecordStatusDto recordStatusDto) throws Exception {
        tblisustampFilesService.commitOrCancelApprove(recordStatusDto);
        return CommonResult.success();
    }
/*    @PostMapping("/createApproval")
    @Operation(summary = "发起流程")
    public CommonResult<Boolean> createApproval(@Valid @RequestBody TblisustampCreateApprovalVO req) {
        tblisustampFilesService.createApproval(req);
        return CommonResult.success(true);
    }

    @PostMapping("/cancelApproval")
    @Operation(summary = "用户取消流程实例", description = "取消发起的流程")
    @PreAuthorize("@ss.hasPermission('doc:B/LIssuingStampApprove:subtable:cancel')")
    public CommonResult<Boolean> cancelProcessInstance(@Valid @RequestBody TblisustampApproveCancelVO req) {
        tblisustampFilesService.cancelProcessInstance(req);
        return success(true);
    }*/
}
